**********************************
* DiD figures (Figures 1 & 2)
**********************************

use ${datafolder}/supermarket_cid_yearmonth_did_sample_real_INR.dta, clear

* Figure 1: Unconditional 2-Group DiD

** Use pre-Demonetization characteristics
merge m:1 cid using ${datafolder}/supermarket_exposure_cid.dta, ///
	keep(match) nogenerate keepusing(treatment_intensity_grp2)

tab yearmonth, gen(monthdummy)

estimates clear
eststo clear

** Panel (A): Use of digital payments over time
eststo reg_noncash_high: reg noncash_amt_pct monthdummy* if inlist(treatment_intensity_grp2,2), noconstant
eststo reg_noncash_low: reg noncash_amt_pct monthdummy* if inlist(treatment_intensity_grp2,1), noconstant

#delimit ;	
coefplot (reg_noncash_high, label(Consumers with Above-Median Prior Cash Dependence) noci recast(connected) lpattern(dash) msymbol(circle))
	(reg_noncash_low, label(Consumers with Below-Median Prior Cash Dependence) noci recast(connected) lpattern(dash_dot) msymbol(diamond) ),
	keep(monthdummy* ) rescale(100)
	vertical xtitle("") ytitle("") omitted nooffsets
	xlabel(1 " Apr 2016" 3 "Jun 2016" 5 "Aug 2016"
	7 "Oct 2016" 9 "Dec 2016" 11 "Feb 2017" 13 "Apr 2017" 15 "Jun 2017" 17 "Aug 2017")
	xline(8, lcolor(blue)) graphregion(style(none) color(white)) bgcolor(white)
	ylabel(20 "20%" 40 "40%" 60 "60%" 80 "80%",
	glcolor(gs14) glpattern(dash) angle(horizontal)) aspect(0.4) msize(small) legend(col(1) region(style(none)))
	graphregion(margin(zero)) plotregion(margin(0 0 0 0)) ysize(2.7) name(did_2group_noncash, replace)
	scheme(s2color);
#delimit cr

** Panel (B): Log spending amount over time
eststo reg_loglevel_high: reg ltender_amt_month monthdummy* if inlist(treatment_intensity_grp2,2), noconstant
eststo reg_loglevel_low: reg ltender_amt_month monthdummy* if inlist(treatment_intensity_grp2,1), noconstant

#delimit ;	
coefplot (reg_loglevel_high, label(Consumers with Above-Median Prior Cash Dependence) noci recast(connected) lpattern(dash) msymbol(circle))
	(reg_loglevel_low, label(Consumers with Below-Median Prior Cash Dependence) noci recast(connected) lpattern(dash_dot) msymbol(diamond) ),
	keep(monthdummy* )
	vertical xtitle("") ytitle("") omitted nooffsets
	xlabel(1 " Apr 2016" 3 "Jun 2016" 5 "Aug 2016"
	7 "Oct 2016" 9 "Dec 2016" 11 "Feb 2017" 13 "Apr 2017" 15 "Jun 2017" 17 "Aug 2017")
	xline(8, lcolor(blue)) graphregion(style(none) color(white)) bgcolor(white)
	ylabel(5(0.5)6.5, glcolor(gs14) glpattern(dash) angle(horizontal)) aspect(0.4) msize(small) legend(col(1) region(style(none)))
	graphregion(margin(zero)) plotregion(margin(0 0 0 0)) ysize(2.8) name(did_2group_loglevel, replace)
	scheme(s2color);
#delimit cr

* Figure 2 Dynamic Effects of Digital Payments on Spending

global controls "treated_month_pre03 treated_month_pre02 treated_month_pre01 "
global controls2 "treated_month_0 treated_month_post01 treated_month_post02 treated_month_post03 treated_month_post04 treated_month_post05 treated_month_post06 treated_month_post07 treated_month_post08 treated_month_post09 treated_month_post10"

estimates clear
eststo clear

** Panel (A): Use of digital payments
eststo reg_dynamic_noncash: reghdfe noncash_amt_pct ${controls} ${controls2}, ///
	 absorb(cid DTCode##yearmonth) vce(cluster cid  yearmonth) nosample noconstant

#delimit ;	
quietly coefplot (reg_dynamic_noncash, label(spend) 
	recast(connected) lpattern(dash) msymbol(circle)) ,  
	keep(treated_month_* ) baselevels  
	vertical xtitle("") ytitle("") omitted offsets  
	xlabel(1 "Aug 2016" 3 "Oct 2016" 5 "Dec 2016" 7 "Feb 2017" 9 "Apr 2017" 11 "Jun 2017" 13 "Aug 2017") 
	ylabel(-0.4(0.1)0.4, glcolor(gs14) glpattern(dash) angle(horizontal))  
	msize(small) legend(off) xline(3.5) aspect(0.5) ysize(2.8)
	graphregion(style(none) color(white) margin(zero) lstyle(none)) plotregion(margin(medium)) bgcolor(white)  
	name(cash, replace)
	scheme(s2color);
#delimit cr

** Panel (B)
eststo reg_dynamic_loglevel: reghdfe ltender_amt_month ${controls} ${controls2}, ///
	 absorb(cid DTCode##yearmonth) vce(cluster cid  yearmonth) nosample noconstant

#delimit ;	
quietly coefplot (reg_dynamic_loglevel, label(spend) 
	recast(connected) lpattern(dash) msymbol(circle)) ,  
	keep(treated_month_* ) baselevels  
	vertical xtitle("") ytitle("") omitted offsets  
	xlabel(1 "Aug 2016" 3 "Oct 2016" 5 "Dec 2016" 7 "Feb 2017" 9 "Apr 2017" 11 "Jun 2017" 13 "Aug 2017") 
	ylabel(-0.4(0.1)0.4, glcolor(gs14) glpattern(dash) angle(horizontal))  
	msize(small) legend(off) xline(3.5) aspect(0.5) ysize(2.8)
	graphregion(style(none) color(white) margin(zero) lstyle(none)) plotregion(margin(medium)) bgcolor(white)  
	name(spending, replace)
	scheme(s2color);
#delimit cr
